package com.Java.train.business.controller;

import com.Java.train.business.entity.DTO.TrainDTO;
import com.Java.train.business.req.TrainQueryReq;
import com.Java.train.business.service.TrainSeatService;
import com.Java.train.business.service.TrainService;
import com.Java.train.common.response.CommonResp;
import com.Java.train.common.response.PageResp;
import com.Java.train.business.entity.Train;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;

import java.util.List;

/**
* @author luomoxingchen
* @since 2024-09-21
*/
@RestController
@RequestMapping("/admin/train")
public class TrainAdminController {

    @Autowired
    private TrainService trainService;

    @Autowired
    private TrainSeatService trainSeatService;

    @GetMapping("/query-list")
    @ApiOperation("Train查询全部")
    public CommonResp<PageResp<TrainDTO>> queryList(@Valid TrainQueryReq trainQueryReq){
        PageResp<TrainDTO> list = trainService.queryList(trainQueryReq);
        return new CommonResp<>(list);
    }

    @PostMapping("/save")
    @ApiOperation("Train修改")
    public CommonResp<Object> update(@Valid @RequestBody Train train) {
        return trainService.modify(train);
    }


    @DeleteMapping(value = "/delete/{ids}")
    @ApiOperation("Train删除(单个条目)")
    public CommonResp<Object> remove(@NotBlank(message = "{required}") @PathVariable String ids) {
        return trainService.remove(ids);
    }

    @GetMapping("/query-all")
    @ApiOperation("Train查询全部")
    public CommonResp<List<TrainDTO>> queryAll(){
        List<TrainDTO> list = trainService.queryAll();
        return new CommonResp<>(list);
    }

    @GetMapping(value = "/gen-seat/{id}")
    @ApiOperation("TrainSeat生成座位数")
    public CommonResp<Object> genSeat(@NotBlank(message = "{required}") @PathVariable(value = "id") String trainCode) {
        return trainSeatService.genSeat(trainCode);
    }
}
